package com.its.test;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @Author: master
 * @Version: 1.0
 */
public class test {

    @Test
    public void t1() {
        //String str1 = "https://images-na.ssl-images-amazon.com/images/I/7128FE2GQJL._AC_UX695_.jpg";
        String str1 = "https://images-na.ssl-images-amazon.com/images/I/71C8kBLqPNL._AC_SX679_.jpg";

        String[] params = str1.split("\\.");
        //System.out.println("值:" + params[3]);
        String jpgValue = params[3].substring(6, params[3].length() - 1);
        System.out.println("jpg:" + jpgValue);
        String newValue = str1.replaceAll(jpgValue, "456");
        System.out.println("原始:" + str1);
        System.out.println("newValue:" + newValue);
    }

    @Test
    public void t2() {
        String str1 = "https://images-na.ssl-images-amazon.com/images/I/71C8kBLqPNL._AC_SX679_.jpg";
        String regex = "_[a-zA-Z]{1,2}_[a-zA-Z]{2}[0-9]{1,3}";
//        String regex = "_[a-zA-Z]{1,2}_[a-zA-Z]{2}";
        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(str1);
        if (m.find()) {
            String findValue = m.group();
            // 精确定位的字符串
            System.out.println(findValue);
            String regexNum = "[0-9]{1,3}";
            p = Pattern.compile(regexNum);
            m = p.matcher(findValue);
            if (m.find()) {
                System.out.println(m.group());
                String newValue = str1.replaceAll(m.group(), "123");
                System.out.println("newValue:" + newValue);
            }
        }
    }
}
